# -*- coding: utf-8 -*-
import os
import json
import platform
from app.tools.pool import PgsqlPool
from tornado.options import options

print('dev configs----------')
# log
log_dir = os.path.join(os.path.dirname(__file__), '../logs/')
if not os.path.exists(log_dir):
    os.mkdir(log_dir)

log_file = os.path.join(os.path.dirname(__file__), '../logs/valkyrja.log')
if os.path.exists(log_file):
    os.remove(log_file)

options.logging = "info"
options.log_to_stderr = True
options.log_file_prefix = log_file
options.log_rotate_mode = "time"
options.log_file_max_size = 1024 * 1024 * 1024
options.log_file_num_backups = 10
options.log_rotate_when = 'D'
options.log_rotate_interval = 1
sys_type = platform.system()

# 1.开发模式下 读取配置文件的方式
# root_path = os.path.dirname(__file__)
#
# if sys_type == 'Windows':
#     root_path = root_path + '\\'
# else:
#     root_path = root_path + '/'
#
# if sys_type == 'Windows':
#     tmp_path = root_path + 'static\\tmp\\'
#
#
# config_path = root_path + 'static/configure/'
# if sys_type == 'Windows':
#     config_path = root_path + 'static\\configure\\'
# file = os.path.join(root_path, "", config_path + "Default.json")

# 2.windows下exe打包情况下，读取配置文件
# 通过环境变量来获取 SafeMonitor目录的路径地址
root_path = os.getenv('Valkyrja_PATH')
real_root_path = os.path.abspath(root_path)
tmp_path =  os.path.join(real_root_path,'app','static','tmp') + '\\'
file = os.path.join(real_root_path,"app","static","configure","Default.json")
#

with open(file, "r", encoding="utf-8") as f:
    global_config = json.load(f)


# 调试模式: 开发者生产模式，debug=True
# 模板路径: template_path
# 静态文件路径: static_path
# 开启跨站伪装登录,xsrf_cookies=True
# 密钥,cookie_secret='uuid'

# 1.开发模式下的配置
configs = dict(
    debug=False,
    autoreload=True,
    template_path=os.path.join(real_root_path, "templates"),
    static_path=os.path.join(real_root_path, "static"),
    xsrf_cookies=False,
    cookie_secret='a1ca2e68bd364596a1c307f804466261'
)

# 2.exe打包模式下
# configs = dict(
#     debug=False,
#     autoreload=True,
#     template_path=os.path.join(root_path, "templates"),
#     static_path=os.path.join(root_path, "static"),
#     xsrf_cookies=False,
#     cookie_secret='a1ca2e68bd364596a1c307f804466261'
# )

kj236_pool = None
if global_config['name'] == "KJ236":
    kj236_db = global_config['kj236_db']
    kj236_pool = PgsqlPool(kj236_db) if kj236_db else None
